/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—05—28
 * Time: 8:01
 */
class Student{
    private int age ;
    public Student(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                '}';
    }
}
public class Test01 {

    public static void main8(String[] args) {
        String str = "   asdasdasdas    ";
        System.out.println(str.trim());//asdasdasdas
    }
    public static void main7(String[] args) {
        String str = "adsasdasdasdasd";
        String ret = str.substring(4,7);//[4,7)
        System.out.println(ret);//sda
    }
    public static void main6(String[] args) {
        String str1 = "Hello this is xawl rjgc professional";
        String[] ret = str1.split(" ");
        for (String s : ret) {
            System.out.println(s);
        }
        String str2 = "192\\188\\12\\1";
        String[] ret1 = str2.split("\\\\");
        for (String s1: ret1) {
            System.out.println(s1);
        }
        String str3 = "avasda asda&sad";
        String[] ret2 = str3.split(" |&");
        for (String s2: ret2) {
            System.out.println(s2);
        }

        String str4 = "asda=sdas&dasd=asd";
        String[] ret3 = str4.split("=");
        for (String s : ret3) {
            String[] s1 = s.split("&");
            for (String x : s1) {
                System.out.println(x);
            }
        }
    }
    public static void main5(String[] args) {
        String str1 = "xawlxawlxawlxawl";
        String ret = str1.replaceAll("xa","B");
        String ret1 = str1.replaceFirst("xa","B");
        System.out.println(ret);//BwlBwlBwlBwl
        System.out.println(str1);//xawlxawlxawlxawl
        System.out.println(ret1);//Bwlxawlxawlxawl
    }
    public static void main4(String[] args) {
        String str = String.valueOf(1234);
        String str1 = String.valueOf(12.34);
        String str2 = String.valueOf(new Student(20));

        System.out.println(str);
        System.out.println(str1);
        System.out.println(str2);
        int a = Integer.valueOf("1234",8);
        System.out.println(a);//668

        String str3 = "abcdef阿凡达";
        String ret = str3.toUpperCase();
        System.out.println(ret);//ABCDEF阿凡达
        String str4 = "ABCDEF阿凡达";
        String ret1 = str4.toLowerCase();
        System.out.println(ret1);//abcdef阿凡达
        System.out.println(str4);//ABCDEF阿凡达

        String str5 = "hello";
        char[] chars = str5.toCharArray();
        for (char x : chars) {
            System.out.println(x);
        }
        char[] chars1 = {'a','b','c'};
        String str6 = new String(chars1);
        System.out.println(str6);//abc

        String str7 = String.format("%d-%d-%d",2022,5,28);
        System.out.println(str7);//2022-5-28
    }
    public static void main3(String[] args) {
        String s1 = "hello";
        String s2 = "helloxawllxhxawllxh";
        for (int i = 0; i < s1.length(); i++) {
            char ch = s1.charAt(i);
            System.out.println(ch+" ");
        }
        int index = s1.indexOf('l',4);
        System.out.println(index);//-1
        int index1 = s1.indexOf('l',3);
        System.out.println(index1);//3
        int index2 = s2.indexOf("xawl",6);
        System.out.println(index2);//12

        int index3 = s2.lastIndexOf('a',7);
        System.out.println(index3);//13

        int index4 = s2.lastIndexOf("xawl",9);
        System.out.println(index4);//5
    }
    public static void main2(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("hello");
        String s3 = new String("world");
        String s4 = new String("HELLO");
        //默认的equals是用来比较地址的
        //而重写的equals就会调用自己写的equals，发生动态绑定
        System.out.println(s1 == s2); // false
        System.out.println(s1.equals(s2));//true

        System.out.println(s2 == s3); // false
        System.out.println(s2.equals(s3));//false

        System.out.println(s1.compareTo(s1));//0
        System.out.println(s2.compareTo(s3));//-15

        //直接比较大小关系
        System.out.println(s1.compareTo(s4));//32
        //忽略大小写进行比较
        System.out.println(s1.compareToIgnoreCase(s4));//0
        //直击比较是否相等
        System.out.println(s1.equals(s4));//false
        //忽略大小写比较是否相等
        System.out.println(s1.equalsIgnoreCase(s4));//true

    }
    public static void main1(String[] args) {
        //1.直接定义一个字符串
        String str = "hello";
        System.out.println(str);
        //2.通过new String对象
        String str2 = new String("xawl");
        System.out.println(str2);
        //3.通过字符数组进行构造
        char[] chars = {'a','b','c'};
        String str3 = new String(chars);
        System.out.println(str3);

        //字符串求长度，length()是一个方法
        System.out.println(str.length());
        //数组求长度
        int[] array = {1,2,3};
        System.out.println(array.length);

        //也可以直接给字符串length() 求长度
        System.out.println("hello".length());
    }
}
